#ifndef __MCS__VARIABLE_ALREADY_DEFINED_EXCEPTION__HPP
#define __MCS__VARIABLE_ALREADY_DEFINED_EXCEPTION__HPP

#include "CompileException.hpp"

class VariableAlreadyDefinedException : public CompileException
{
public:
	VariableAlreadyDefinedException(String const & name, SourceLocation const & location, SourceLocation const & previousLocation)
		: CompileException(location)
		, name_(name)
		, previousLocation_(previousLocation)
	{
	}

	String name() const { return name_; }
	SourceLocation const & previousLocation() const { return previousLocation_; }

	virtual std::ostream & stream(std::ostream & str) const
	{
		return CompileException::stream(str) << "variable named \"" << name_ << "\" is already defined at " << previousLocation_;
	}
private:
	String name_;
	SourceLocation previousLocation_;
};

#endif //__MCS__VARIABLE_ALREADY_DEFINED_EXCEPTION__HPP
